package com.wdh.networklibrary.utils;

import android.content.Context;
import android.os.Handler;
import android.util.TypedValue;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.wdh.networklibrary.R;


public class SwipeUtil {

    public static void initSwipe(SwipeRefreshLayout mSwipe, Context context) {

        mSwipe.setColorSchemeResources(R.color.colorPrimary, R.color.colorPrimaryDark, R.color.colorAccent);//设置进度动画的颜色
        if (context != null) {
            mSwipe.setProgressViewOffset(true, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                    24, context.getResources().getDisplayMetrics()));
        }

    }

    public static void showSwipe(SwipeRefreshLayout mSwipe,boolean refresh){
        if (refresh) {
            mSwipe.setRefreshing(true);
        } else {
            new Handler().postDelayed(() -> {
                try {
                    mSwipe.setRefreshing(false);
                } catch (NullPointerException e) {
                    e.getMessage();
                }
            }, 600);//延时消失加载的loading
        }
    }
}
